package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.HmzEmployeeInfo;
import com.ruoyi.system.mapper.HmzEmployeeInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HmzRechargeRecordsMapper;
import com.ruoyi.system.domain.HmzRechargeRecords;
import com.ruoyi.system.service.IHmzRechargeRecordsService;

/**
 * 充值记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-01
 */
@Service
public class HmzRechargeRecordsServiceImpl implements IHmzRechargeRecordsService
{
    @Autowired
    private HmzRechargeRecordsMapper hmzRechargeRecordsMapper;
    @Autowired
    private HmzEmployeeInfoMapper hmzEmployeeInfoMapper;
    /**
     * 查询充值记录
     *
     * @param id 充值记录主键
     * @return 充值记录
     */
    @Override
    public HmzRechargeRecords selectHmzRechargeRecordsById(Long id)
    {
        return hmzRechargeRecordsMapper.selectHmzRechargeRecordsById(id);
    }

    /**
     * 查询充值记录列表
     *
     * @param hmzRechargeRecords 充值记录
     * @return 充值记录
     */
    @Override
    public List<HmzRechargeRecords> selectHmzRechargeRecordsList(HmzRechargeRecords hmzRechargeRecords) {
        // 查询员工名称
        List<HmzRechargeRecords> hmzRechargeRecords1 = hmzRechargeRecordsMapper.selectHmzRechargeRecordsList(hmzRechargeRecords);
        if (hmzRechargeRecords1 != null && hmzRechargeRecords1.size() > 0) {
            for (HmzRechargeRecords record : hmzRechargeRecords1) {
                // 循环用员工id获取员工名称
                HmzEmployeeInfo employeeInfo = hmzEmployeeInfoMapper.selectHmzEmployeeInfoById(record.getEmployeeId());
                if (employeeInfo != null) {
                    record.setEmployeeName(employeeInfo.getName());
                } else {
                    record.setEmployeeName("未知员工");
                }
            }
            // 打印第一个记录的员工名称，用于调试
            System.out.printf("员工信息: %s\n", hmzRechargeRecords1.get(0).getEmployeeName());
        }
        return hmzRechargeRecords1;
    }



    /**
     * 新增充值记录
     *
     * @param hmzRechargeRecords 充值记录
     * @return 结果
     */
    @Override
    public int insertHmzRechargeRecords(HmzRechargeRecords hmzRechargeRecords)
    {
        hmzRechargeRecords.setCreateTime(DateUtils.getNowDate());
        return hmzRechargeRecordsMapper.insertHmzRechargeRecords(hmzRechargeRecords);
    }

    /**
     * 修改充值记录
     *
     * @param hmzRechargeRecords 充值记录
     * @return 结果
     */
    @Override
    public int updateHmzRechargeRecords(HmzRechargeRecords hmzRechargeRecords)
    {
        hmzRechargeRecords.setUpdateTime(DateUtils.getNowDate());
        return hmzRechargeRecordsMapper.updateHmzRechargeRecords(hmzRechargeRecords);
    }

    /**
     * 批量删除充值记录
     *
     * @param ids 需要删除的充值记录主键
     * @return 结果
     */
    @Override
    public int deleteHmzRechargeRecordsByIds(Long[] ids)
    {
        return hmzRechargeRecordsMapper.deleteHmzRechargeRecordsByIds(ids);
    }

    /**
     * 删除充值记录信息
     *
     * @param id 充值记录主键
     * @return 结果
     */
    @Override
    public int deleteHmzRechargeRecordsById(Long id)
    {
        return hmzRechargeRecordsMapper.deleteHmzRechargeRecordsById(id);
    }
}
